package com.forekonw.demo10;

public class UserManager {
    String[] name = new String[2];
    String[] pass = new String[2];


    public void register(String uname,String upass) throws CustomException{
        //查看字符串String的长度
        int nlength = uname.length();
        int plength = upass.length();
        //验证用户名和密码是否为空
        if (uname.equals("")||upass.equals("")){
            throw new CustomException("输入的用户名及密码为空");
        }
        if (nlength<6||nlength>14){
            throw new CustomException("用户的长度不符合规范");
        }
        if (plength<8 || plength>16){
            throw new CustomException("密码的长度不符合规范");
        }

        for (int i =0;i< name.length;i++){
            if (name[i]==null&&pass[i]==null){
                name[i] = uname;
                pass[i] = upass;
                System.out.println("注册成功了");
                return;//方法中遇到return方法就结束了
            }
        }
        throw new CustomException("无法注册了");
    }


    public static void main(String[] args) {
        UserManager u = new UserManager();
        try {
            u.register("tom" , "2345");
        } catch (CustomException e) {
            e.printStackTrace();
        }

        System.out.println("11111111111111");
    }
}
